#include "PlaneAsset.h"

PlaneAsset::PlaneAsset()
  : GameAsset(
	      string("shaders/hello-gl.v.glsl")
	      , string("shaders/hello-gl.f.glsl")
	      )
{
  PlaneAsset(0, 0, 0);
}

GLfloat g_vertex_buffer_data;

PlaneAsset::PlaneAsset(float x, float y, float z) {
  this->li = nullptr;
  this->pos = shared_ptr<Point3>(new Point3(x, y, z));
  // A default "unit" triangular pyramid
  num_vertices = 4;
  num_triangles = 2;
  g_vertex_buffer_data = new GLfloat[num_vertices * 3] // three points per vertex
  //vertices
  //	X 	  Y		Z
  {
	  -5.0, -5.0, +0.25,//0
	  -5.0, +5.0, +0.25,//1
	  +5.0, -5.0, +0.25,//2
	  +5.0, +5.0, +0.25,//3
  };
  g_element_buffer_data = new GLushort[num_triangles * 3] // three vertices per triangle
  //triangles
  //1 2 3
  {
	0,1,2,//0
	1,2,3,//1
  };

  mv_matrix = mv_matrix.translation(Vector3(x, y, z));
  bbox.reset();
  bbox = shared_ptr<BoundingBox>(new BoundingBox(Point3(x, y, z), 1.0, 1.0, 1.0));

  make_resources();
}

PlaneAsset::PlaneAsset(float x, float y, float z, string file)
	: GameAsset(string("shaders/hello-gl.v.glsl"), string(file)){
	  this->li = nullptr;
	  this->pos = shared_ptr<Point3>(new Point3(x, y, z));
	  // A default "unit" triangular pyramid
	  num_vertices = 4;
	  num_triangles = 2;
	  g_vertex_buffer_data = new GLfloat[num_vertices * 3] // three points per vertex
	  //vertices
	  //	X 	  Y		Z
	  {
		  -5.0, -5.0, +0.25,//0
		  -5.0, +5.0, +0.25,//1
		  +5.0, -5.0, +0.25,//2
		  +5.0, +5.0, +0.25,//3
	  };
	  g_element_buffer_data = new GLushort[num_triangles * 3] // three vertices per triangle
	  //triangles
	  //1 2 3
	  {
			0,1,2,//0
			1,2,3,//1
	  };

	  mv_matrix = mv_matrix.translation(Vector3(x, y, z));
	  bbox.reset();
	  bbox = shared_ptr<BoundingBox>(new BoundingBox(Point3(x, y, z), 1.0, 1.0, 1.0));

	  make_resources();
}

PlaneAsset::~PlaneAsset() {
  // TODO: do something nice here.
}

void PlaneAsset::update() {
}

void PlaneAsset::setInterpolator(shared_ptr<IInterpolator> li) {
  this->li.swap(li);
}

void PlaneAsset::draw() {
  GameAsset::draw();
}

void PlaneAsset::scale(float x, float y, float z){
	mv_matrix = mv_matrix * Matrix4::scale(Vector3(x, y, z));
}
